package cn.zcy.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 自定义规则
 */
public class LinuxCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //1.获取环境信息
        Environment environment = context.getEnvironment();
        //2.获取当前系统的名称
        String osName=environment.getProperty("os.name");
        //3.判断是否包含windows规则
        if (osName.contains("Linux")){
            //需要注册到IOC
            return true;
        }
        //不需要注册到IOC容器中
        return false;
    }
}
